package binarysearch

// 返回x的算术平方根
func mySqrt(x int) int {
	// a*a = x  在[0,x]范围内搜索a
	if x==0 {
		return 0
	}
	// [1,x]
	left,right := 1,x
	for left<=right {
		mid := left+(right-left)/2
		if mid*mid == x {
			return x
		}else if mid*mid<x {
			left = mid+1
		}else{
			right = mid-1
		}
	}
	// 不是整数 8-2   
	return right
}